package com.usb.serial.device.util;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import java.util.Arrays;
import java.util.List;

public class SnModelUtil implements LifecycleObserver {
    private String[] snManager = {};
    private String x;
    private error error;

    public SnModelUtil(Context context) {
        x = xx(context);
    }

    public void setError(SnModelUtil.error error) {
        this.error = error;
    }

    public List<String> getSnManager() {
        return Arrays.asList(snManager);
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void start() {
        if (!getSnManager().contains(x)) {
            if (error != null) {
                error.error();
            }
            return;
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {

    }


    public static String xx(Context context) {
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
            @SuppressLint("MissingPermission") String x = telephonyManager.getDeviceId();
            return x;
        }catch (Exception e){
            e.printStackTrace();
            return "123321";

        }

    }

    public interface error {
        void error();
    }


}
